package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIActionGroupDAO;
import com.ourteam.product.ui.dao.ProductUIActionGroup;
import com.ourteam.product.ui.dao.ProductUIActionGroupDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:16 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIActionGroupDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIActionGroupDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        DomainId,
        ActionGroupCode,
        LastModifyUser,
        LastModifyTime,
        Status,
        Remarks,
        DomainName,
        DomainCode
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.DomainId,
        _DataObjectProperty.ActionGroupCode,
        _DataObjectProperty.LastModifyUser,
        _DataObjectProperty.LastModifyTime,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.DomainName,
        _DataObjectProperty.DomainCode
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIActionGroup, ProductUIActionGroupDAOQueryBean> daoHelper;

  public AbstractProductUIActionGroupDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<ProductUIActionGroup, ProductUIActionGroupDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName)
          .append(" PRODUCT_UI_DOMAIN ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIDomainDAO.Id,
              com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName + ".",
              "PRODUCT_UI_DOMAIN."));
      relatedJoinSQLBuffer.append(" = ").append(DomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIActionGroup
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIActionGroup aProductUIActionGroup) throws Exception {

    if (aProductUIActionGroup == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIActionGroup.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIActionGroup
   * @throws Exception
   */
  public void insert(ProductUIActionGroup aProductUIActionGroup) throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroup,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doInsert(aProductUIActionGroup);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIActionGroup
   * @throws Exception
   */
  public void batchInsert(ProductUIActionGroup[] aProductUIActionGroups) throws Exception {

    super.doBatchInsert(aProductUIActionGroups);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIActionGroup aProductUIActionGroup) throws Exception {

    delete(aProductUIActionGroup.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIActionGroup
   * @throws Exception
   */
  public void update(ProductUIActionGroup aProductUIActionGroup) throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroup,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    if (aProductUIActionGroup.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIActionGroup);

    ProductUIActionGroup tempObj = findById(aProductUIActionGroup.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIActionGroup, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIActionGroups[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIActionGroup[] aProductUIActionGroups) throws Exception {

    super.doBatchUpdate(aProductUIActionGroups);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIActionGroup
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      ProductUIActionGroup aProductUIActionGroup, ProductUIActionGroupDAOQueryBean aQueryBean)
      throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroup,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doUpdateByQuery(aProductUIActionGroup, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIActionGroupDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIActionGroup aProductUIActionGroup) throws Exception {

    if (aProductUIActionGroup.getActionGroupCode() == null) {
      throw new Exception("The ProductUIActionGroup.actionGroupCode value is not allow NULL");
    }

    if (aProductUIActionGroup.getLastModifyUser() == null) {
      throw new Exception("The ProductUIActionGroup.lastModifyUser value is not allow NULL");
    }

    if (aProductUIActionGroup.getLastModifyTime() == null) {
      throw new Exception("The ProductUIActionGroup.lastModifyTime value is not allow NULL");
    }

    if (aProductUIActionGroup.getStatus() == null) {
      throw new Exception("The ProductUIActionGroup.status value is not allow NULL");
    }

    if (aProductUIActionGroup.getRemarks() == null) {
      throw new Exception("The ProductUIActionGroup.remarks value is not allow NULL");
    }

    if (aProductUIActionGroup.getDomainName() == null) {
      throw new Exception("The ProductUIActionGroup.domainName value is not allow NULL");
    }

    if (aProductUIActionGroup.getDomainCode() == null) {
      throw new Exception("The ProductUIActionGroup.domainCode value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIActionGroup findById(final long id) throws Exception {

    ProductUIActionGroupDAOQueryBean queryBean = new ProductUIActionGroupDAOQueryBean();

    ProductUIActionGroupDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIActionGroup[] ProductUIActionGroups = query(queryBean);

    if (ProductUIActionGroups.length == 0) {
      return null;
    } else {
      return ProductUIActionGroups[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIActionGroup[]
   * @throws Exception
   */
  public ProductUIActionGroup[] query(ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIActionGroupRowMapper());

    return (ProductUIActionGroup[]) result.toArray(new ProductUIActionGroup[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIActionGroupDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUIActionGroup[] aProductUIActionGroups, ProductUIActionGroupDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIActionGroups, queryBean);
  }

  public void synchronize(
      ProductUIActionGroup[] aProductUIActionGroups,
      ProductUIActionGroupDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIActionGroup> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIActionGroups, queryBean, callBack);
  }

  private com.ourteam.product.ui.dao.impl.AbstractProductUIActionGroupRelateDAOJdbcImpl
      ProductUIActionGroupRelateDao;

  public void setProductUIActionGroupRelateDao(
      com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO ProductUIActionGroupRelateDao) {
    this.ProductUIActionGroupRelateDao =
        (com.ourteam.product.ui.dao.impl.AbstractProductUIActionGroupRelateDAOJdbcImpl)
            ProductUIActionGroupRelateDao;
  }

  /**
   * Query Related ProductUIActionGroupRelate
   *
   * @param queryBean
   * @throws Exception
   */
  public com.ourteam.product.ui.dao.ProductUIActionGroupRelate[] queryProductUIActionGroupRelate(
      ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ActionGroupId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.EntityName
            + " ref_ProductUIActionGroupRelate";

    String[] entityFields =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.ENTITY_FIELDS;

    String[] entityProperties =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.ENTITY_PROPERTIES;

    List list =
        ProductUIActionGroupRelateDao.doQuery(
            entityName,
            entityFields,
            entityProperties,
            queryBean,
            joinSQL.toString(),
            new com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO
                .JdbcProductUIActionGroupRelateRowMapper());

    return (com.ourteam.product.ui.dao.ProductUIActionGroupRelate[])
        list.toArray(new com.ourteam.product.ui.dao.ProductUIActionGroupRelate[list.size()]);
  }

  /**
   * Query Related ProductUIActionGroupRelate Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] queryProductUIActionGroupRelateSelective(
      ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Id, "id");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ActionGroupId, "actionGroupId");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.RelatedActionId,
          "relatedActionId");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Handler, "handler");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Icon, "icon");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.LabelText, "labelText");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.LabelKey, "labelKey");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ConfirmInfo, "confirmInfo");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ConfirmInfoKey,
          "confirmInfoKey");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.LastModifyUser,
          "lastModifyUser");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.LastModifyTime,
          "lastModifyTime");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.SortIndex, "sortIndex");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Status, "status");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Remarks, "remarks");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.VisibleScript, "visibleScript");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.MenuListId, "menuListId");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.DisableScript, "disableScript");

      queryBean.addSelectProperty(
          com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.Style, "style");
    }

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ActionGroupId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.EntityName
            + " ref_ProductUIActionGroupRelate";

    return ProductUIActionGroupRelateDao.doQuerySelective(
        entityName, queryBean, joinSQL.toString());
  }

  /**
   * Update Related ProductUIActionGroupRelate
   *
   * @param aProductUIActionGroupRelate
   * @param aQueryBean
   * @model
   * @throws Exception
   */
  public void updateProductUIActionGroupRelate(
      com.ourteam.product.ui.dao.ProductUIActionGroupRelate aProductUIActionGroupRelate,
      ProductUIActionGroupDAOQueryBean aQueryBean)
      throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ActionGroupId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.EntityName
            + " ref_ProductUIActionGroupRelate";

    String[] entityFields =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.ENTITY_FIELDS;

    String[] entityProperties =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO.ENTITY_PROPERTIES;

    ProductUIActionGroupRelateDao.doUpdateByQuery(
        entityName,
        entityFields,
        entityProperties,
        joinSQL.toString(),
        aProductUIActionGroupRelate,
        aQueryBean);
  }

  /**
   * Delete Related ProductUIActionGroupRelate
   *
   * @param aQueryBean
   * @model
   * @throws Exception
   */
  public void deleteProductUIActionGroupRelate(ProductUIActionGroupDAOQueryBean aQueryBean)
      throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO.ActionGroupId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.product.ui.dao.impl.ProductUIActionGroupRelateDAO
            .EntityName; // + " ref_ProductUIActionGroupRelate";

    ProductUIActionGroupRelateDao.doDeleteByQuery(entityName, joinSQL.toString(), aQueryBean);
  }

  public static class JdbcProductUIActionGroupRowMapper implements RowMapper<ProductUIActionGroup> {

    public ProductUIActionGroup mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIActionGroup object = new ProductUIActionGroup();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object domainId = null;

        domainId = resultSet.getObject(columnIndex++);

        object.setDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (domainId != null) {

          setBeanValue(object, _DataObjectProperty.DomainId, domainId);
        }

        Object actionGroupCode = null;

        actionGroupCode = resultSet.getObject(columnIndex++);

        object.setActionGroupCodeNull(resultSet.getBoolean(columnIndex++));

        if (actionGroupCode != null) {

          setBeanValue(object, _DataObjectProperty.ActionGroupCode, actionGroupCode);
        }

        Object lastModifyUser = null;

        lastModifyUser = resultSet.getObject(columnIndex++);

        object.setLastModifyUserNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyUser != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyUser, lastModifyUser);
        }

        Object lastModifyTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastModifyTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastModifyTime = resultSet.getObject(columnIndex++);
        }

        object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyTime != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyTime, lastModifyTime);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object domainName = null;

        domainName = resultSet.getObject(columnIndex++);

        object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (domainName != null) {

          setBeanValue(object, _DataObjectProperty.DomainName, domainName);
        }

        Object domainCode = null;

        domainCode = resultSet.getObject(columnIndex++);

        object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

        if (domainCode != null) {

          setBeanValue(object, _DataObjectProperty.DomainCode, domainCode);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
